#include "redlesiondetection.h"
#include "funduspreprocessing.h"

using namespace pip;
using namespace std;


int main(int argc, char *argv[]){
  string program = argv[0];
  vector<string> args(argv, argv+argc);
  if (argc<2)
    error(program, "\nUsage: redlesiondetection filename -orientations n -elementlength m\n"
	  "Isolates redlesions in a preprocessed fundus image with a black top-hat transform.\n"
	  "It uses a linear structure element of length m, rotated over n orientations.\n");

  //get filename, color and medianwidth from command line
  string filename  = argv[1];
  int orientations = 1;
  getScalarArg(args, "-orientations", orientations);
  if(orientations<0){
    error(program, "Not a valid number of orientations.\n");
    return 1;
  }
  int elementlength = 1;
  getScalarArg(args, "-elementlength", elementlength);
  if(elementlength<0){
    error(program, "Not a structure element length.\n");
    return 1;
  }

  Image<float> imIn;
  Image<float> imOut;
  if (!importFile(imIn,filename))
    error(program, "Error reading input file (must be 2D gray-scale pip image)\n");

  RedLesionDetector<float> rld;
  rld.setNrOfOrientations(orientations);
  rld.setElementLength(elementlength);
  rld.run(imIn,imOut);

  // Print min/max/average
  float min, max, avr;
  getMinMaxAvrImage<float>(imOut,min, max, avr);
  cout << "After black top-hat transform : " << endl;
  cout << "|" << orientations <<"|" << elementlength << "|"<<min<< "|"<<max<< "|"<<avr<< "|"<<"|" << endl;// in this way i can paste it into the wiki easier...

  // save the result image
  exportFile(imOut,"fundus_rld.pip");

  return 0;
}
